﻿using System;
using System.Collections.Generic;
using System.Globalization;

namespace MapDownloader.Core.Models
{
   /// <summary>
   ///    像素坐标
   /// </summary>
   [Serializable]
   public struct PixelPoint
   {
      public static readonly PixelPoint Empty = new PixelPoint();

      /// <summary>
      ///    X
      /// </summary>
      public float X { get; }

      /// <summary>
      ///    Y
      /// </summary>
      public float Y { get; }

      public PixelPoint(float x, float y)
      {
         X = x;
         Y = y;
      }

      /// <summary>
      ///    是否是空点
      /// </summary>
      public bool IsEmpty => X.Equals(0) && Y.Equals(0);


      /// <summary>
      ///    重载
      /// </summary>
      /// <param name="obj"></param>
      /// <returns></returns>
      public override bool Equals(object obj)
      {
         if (!(obj is PixelPoint))
            return false;
         var comp = (PixelPoint) obj;
         return comp.X.Equals(X) && comp.Y.Equals(Y);
      }

      /// <summary>
      ///    重载
      /// </summary>
      /// <returns></returns>
      public override int GetHashCode()
      {
         return X.GetHashCode() ^ Y.GetHashCode();
      }


      /// <summary>
      ///    ToString
      /// </summary>
      /// <returns></returns>
      public override string ToString()
      {
         return "{X=" + X.ToString(CultureInfo.CurrentCulture) + ",Y=" + Y.ToString(CultureInfo.CurrentCulture) + "}";
      }
   }

   internal class PixelPointComparer : IEqualityComparer<PixelPoint>
   {
      public bool Equals(PixelPoint x, PixelPoint y)
      {
         return x.X.Equals(y.X) && x.Y.Equals(y.Y);
      }

      public int GetHashCode(PixelPoint obj)
      {
         return obj.GetHashCode();
      }
   }
}